package com.vitabuybuy.tv.ui.shopcenter.adapter

import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.vitabuybuy.tv.R
import com.vitabuybuy.tv.databinding.ItemClassificationBinding
import com.vitabuybuy.tv.dto.ClassificationDto
import com.library.common.base.BindRecycAdapter

class SecondClassificationAdapter : BindRecycAdapter<ItemClassificationBinding,ClassificationDto.ChildrenBean>(){

    private var categoryAdapter : CategoryAdapter? = null

    override fun onBindViewHolder(
        mBinding: ItemClassificationBinding,
        itemData: ClassificationDto.ChildrenBean,
        holder: RecyclerView.ViewHolder,
        position: Int
    ) {
        mBinding.itemData = itemData
        categoryAdapter = CategoryAdapter()
        mBinding.listview.apply {
            adapter = categoryAdapter
            layoutManager = GridLayoutManager(mContext, 3)
        }
        categoryAdapter?.setNewData(itemData.children)

        categoryAdapter?.setOnItemClickListener { _, item, _ ->
            onClick(item)
        }
    }

    lateinit var onClick:(ClassificationDto.ChildrenBean.ChildrenBean2)->Unit

    override fun normalViewId(viewType: Int): Int {
        return R.layout.item_classification
    }
}
